
#ifndef XDNS_ENCODER_H
#define XDNS_ENCODER_H

#include "xdns.h"

class XdnsData;

/*! Handle protocol encoding for both TCP and UDP. */
class XdnsEncoder
{
public:
    /*! Generate the data of DNS request for both TCP and UDP to send.

        @param id ID saved in the header.
        @param qtype QTYPE saved in the question section.
        @param qclass QCLASS saved in the question section.
        @param name QNAME saved in the question section.
        @param data On return the generated data of DNS request. The
                    total data size is saved in the first 2 bytes for
                    TCP to send, but it is useless for UDP. So the
                    start offset of TCP is 0 and UDP is 2.
        @return XE_Ok if success.
    */
    static XdnsError GenerateData(unsigned short id,
                                  unsigned short qtype,
                                  unsigned short qclass,
                                  const std::string& name,
                                  XdnsData& data);

    /*! Reset the ID in the generated data.

        @param id ID reset in the header.
        @param data The data has already been generated by the function
                    GenerateData before.
        @see GenerateData.
        @return XE_Ok if success.
    */
    static XdnsError ResetId(unsigned short id,
                             XdnsData& data);

private:
    XdnsEncoder();
    ~XdnsEncoder();
};

#endif  // XDNS_ENCODER_H

